/**
 * 
 */
package com.onstar.cn.map.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.text.Html;
import android.text.Spanned;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.services.core.LatLonPoint;
import com.onstar.cn.map.common.Language;

public class MapUtil {
	/**
	 * AMap瀵硅薄鍒ゆ柇鏄惁涓簄ull
	 */
	public static boolean checkReady(Context context, AMap aMap) {
		return aMap != null;
	}

	public static Spanned stringToSpan(String src) {
		return src == null ? null : Html.fromHtml(src.replace("\n", "<br />"));
	}

	public static String colorFont(String src, String color) {
		StringBuffer strBuf = new StringBuffer();

		strBuf.append("<font color=").append(color).append(">").append(src)
				.append("</font>");
		return strBuf.toString();
	}

	public static String makeHtmlNewLine() {
		return "<br />";
	}

	public static String makeHtmlSpace(int number) {
		final String space = "&nbsp;";
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < number; i++) {
			result.append(space);
		}
		return result.toString();
	}

	public static String getFriendlyLength(float lenMeter, Language lan) {
		DecimalFormat fnum = new DecimalFormat("##0.00");
		
		String km = ChString.Kilometer;
		String meter = ChString.Meter;
		if (lan == Language.EN_US) {
			km = ChString.EN_KILOMETER;
			meter = ChString.EN_METER;
		}
		
		if (lenMeter > 10000) // 10 km
		{
			float dis = lenMeter / 1000;
			String dstr = fnum.format(dis);
			return dstr + km;
		}

		if (lenMeter > 1000) {
			float dis = lenMeter / 1000;
			String dstr = fnum.format(dis);
			return dstr + km;
		}

		if (lenMeter > 100) {
			float dis = lenMeter / 50 * 50;
			String dstr = fnum.format(dis);
			return dstr + meter;
		}

		float dis = lenMeter / 10 * 10;
		if (dis == 0) {
			dis = 10;
		}
		String dstr = fnum.format(dis);
		return dstr + meter;
	}

	public static boolean IsEmptyOrNullString(String s) {
		return (s == null) || (s.trim().length() == 0);
	}

	/**
	 * 鎶奓atLng瀵硅薄杞寲涓篖atLonPoint瀵硅薄
	 */
	public static LatLonPoint convertToLatLonPoint(LatLng latlon) {
		return new LatLonPoint(latlon.latitude, latlon.longitude);
	}

	/**
	 * long绫诲瀷鏃堕棿鏍煎紡鍖?
	 */
	public static String convertToTime(long time) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date(time);
		return df.format(date);
	}
	
	public static String convertToHumanTime(float seconds, String hour, String minute){
		int hours = (int) seconds/3600;
		float min = seconds%3600;
		int mins = (int)min/60;
		
		return hours+hour+mins+minute;
		
	}

	public static final String HtmlBlack = "#000000";
	public static final String HtmlGray = "#808080";
}
